<template>
  <div class="">
    <!-- app-container -->
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true" :label-width="labelWidth">
        <el-form-item label="使用状态：" prop="">
          <el-select v-model="queryParams.couponStatus" placeholder="请选择" filterable clearable
            :style="{width: inputWidth}">
            <el-option v-for="dict in orderCouponStatus" :key="dict.id" :label="dict.value" :value="dict.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="支付状态：" prop="">
          <el-select v-model="queryParams.status" placeholder="请选择" filterable clearable
            :style="{width: inputWidth}">
            <el-option v-for="dict in statusLs" :key="dict.id" :label="dict.value" :value="dict.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单类型：" prop="">
          <el-select v-model="queryParams.orderType" placeholder="请选择" filterable clearable :style="{width: inputWidth}">
            <el-option v-for="(item,index) in activityOrderType" :key="index" :label="item.value" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单编号：" prop="">
          <el-input v-model="queryParams.orderNo" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="活动名称：" prop="">
          <el-input v-model="queryParams.activityName" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="备注：" prop="">
          <el-input v-model="queryParams.remark" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="会员姓名：" prop="">
          <el-input v-model="queryParams.customerName" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="手机号码：" prop="">
          <el-input v-model="queryParams.phone" placeholder="请输入" clearable :style="{width: inputWidth}" />
        </el-form-item>
        <el-form-item label="下单时间：" prop="">
          <el-date-picker v-model="date" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>

        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <div class="num_detail">
          <div class="num_detail_box">销售数量：{{info.sellCount}}</div>
          <div class="num_detail_box">销售金额：￥{{info.sellMoney}}</div>
          <div class="num_detail_box">退款数量：{{info.refundCount}}</div>
          <div class="num_detail_box">退款金额：￥{{info.refundMoney}}</div>
          <div class="num_detail_box">部分使用：{{info.verificationCount}}</div>
          <div class="num_detail_box">已完成：{{info.completeCount}}</div>
          <div class="num_detail_box">赠送椰分：{{info.giveTfAmount}}</div>
          <div class="num_detail_box">赠送CoCo：{{info.giveCoCoAmount}}</div>
          <div class="num_detail_box">活动个数：{{info.activityCount}}</div>
          <div class="num_detail_box">参与人数：{{info.customerCount}}</div>
        </div>
        <export-excel-button title="打卡活动订单" action="/shenye/punch/activity/order/export" :params="ExportParams" />
      </div>
      <el-table v-loading="loading" :data="tabList" stripe border>
        <el-table-column label="序号" align="center" type="index" width="64px" />
        <el-table-column label="订单编号" align="center" prop="orderNo" />
        <el-table-column label="订单类型" align="center" prop="orderType" :show-overflow-tooltip="true" width="120px">
          <template slot-scope="scope">
            <dict-tag :options="activityOrderType" :value="scope.row.orderType" />
          </template>
        </el-table-column>
        <el-table-column label="活动名称" align="center" prop="activityName" />
        <el-table-column label="姓名" align="center" prop="customerName" />
        <el-table-column label="手机号" align="center" prop="phone" width="108" />
        <el-table-column label="支付状态" align="center" prop="couponStatus" :show-overflow-tooltip="true" width="120px">
          <template slot-scope="scope">
            <dict-tag :options="statusLs" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="使用状态" align="center" prop="couponStatus" :show-overflow-tooltip="true" width="120px">
          <template slot-scope="scope">
            <dict-tag :options="orderCouponStatus" :value="scope.row.couponStatus" v-if="scope.row.couponStatus!=''" />
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="订单金额" align="center" prop="orderMoney" />
        <el-table-column label="积分支付" align="center" prop="integralUseAmount" />
        <el-table-column label="优惠金额" align="center" prop="discountMoney" />
        <el-table-column label="实付金额" align="center" prop="payMoney" />
        <el-table-column label="下单时间" align="center" prop="transactionTime" width="100" />
        <el-table-column label="勋章加成" align="center" prop="verificationProductionValue" />
        <el-table-column label="激励资产" align="center" prop="verificationGiveAmount" />
        <el-table-column label="贡献点" align="center" prop="contribution" />
        <el-table-column label="退款金额" align="center" prop="refundMoney" />
        <el-table-column label="退回积分" align="center" prop="integralRefundAmount" />
        <el-table-column label="退款时间" align="center" prop="refundTime" width="100" />
        <el-table-column label="平台佣金" align="center" prop="commission" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="couponNoDialogClick(scope.row)">查看券码</el-button>
            <el-button size="mini" type="text" @click="applicationClick(scope.row)" v-if="scope.row.couponStatus==1">退款申请</el-button>
            <el-button size="mini" type="text" @click="refundClick(scope.row)" v-if="scope.row.couponStatus==4">退款</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <!-- 退款弹窗 -->
    <RefundDialog :id="dialogId" v-bind="$attrs" v-if="dialogVisible" :visible.sync="dialogVisible"
      @success="_handleSuccess">
    </RefundDialog>
    <applicationDialog :id="dialogId" v-bind="$attrs" v-if="applicationVisible" :visible.sync="applicationVisible"
      @success="_handleSuccess">
    </applicationDialog>
    <!-- 查看券码弹窗 -->
    <CouponNoDialog :orderType="orderType" :id="dialogId" v-bind="$attrs" v-if="couponNoDialogVisible"
      :visible.sync="couponNoDialogVisible" @success="_handleSuccess">
    </CouponNoDialog>
  </div>
</template>

<script>
  import {
    activityOrderList,
    activityOrderCount,
  } from "@/api/consumeMiningManagement/clockingActivityOrder";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  import RefundDialog from "@/views/consumeMiningManagement/clockingActivityOrder/components/refundDialog"; 
  import applicationDialog from "@/views/consumeMiningManagement/clockingActivityOrder/components/applicationDialog"; 
  import CouponNoDialog from "@/views/consumeMiningManagement/clockingActivityOrder/components/couponNoDialog";
  export default {
    // dicts: ['equity_card_issue_type', 'equity_card_sell_status'],
    name: "",
    components: {
      ExportExcelButton,
      RefundDialog,
      applicationDialog,
      CouponNoDialog
    },
    data() {
      return {
        labelWidth: '100px',
        inputWidth: '200px',
        //日期
        date: [],
        // 遮罩层
        loading: false,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 表格数据
        tabList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          activityName: '', //活动名称
          buyEndTime: '', //下单结束时间
          buyStartTime: '', //下单开始时间
          couponStatus: '', //使用状态 shenye_punch_activity_order_coupon_status	
          customerName: '', //姓名
          orderNo: '', //订单编号
          orderType: '', //订单类型 shenye_punch_activity_order_type
          phone: '', //手机号码
          remark: '', //备注
          status:'',//支付状态 customer_shenye_groupon_order_status
        },
        orderCouponStatus: [], //使用状态下拉
        activityOrderType: [], //订单类型下拉
        statusLs:[],//支付状态
        info: {},
        dialogVisible: false, //弹窗状态
        applicationVisible: false,
        couponNoDialogVisible: false, //查看券码弹窗状态
        orderType: '', //券类型
        dialogId: '', //弹窗id
      };
    },
    computed: {
      ExportParams() {
        const params = {
          ...this.queryParams,
        };
        return params;
      },
    },
    created() {
      this.getOrderCouponStatus();
      this.getActivityOrderType();
      this.getList();
      this.getActivityOrderCount()
    },
    methods: {
      //获取使用状态、支付状态字典
      getOrderCouponStatus() {
        var dictType = "shenye_punch_activity_order_coupon_status,customer_shenye_groupon_order_status";
        this.$getSelectList(dictType)
          .then((res) => {
            var arr = [{
              id: "",
              value: "全部",
            }, ];
            this.orderCouponStatus = arr.concat(res.result[0].dictList);
            this.statusLs = arr.concat(res.result[1].dictList);
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取订单类型字典
      getActivityOrderType() {
        var dictType = "shenye_punch_activity_order_type";
        this.$getSelectList(dictType)
          .then((res) => {
            var arr = [{
              id: "",
              value: "全部",
            }, ];
            this.activityOrderType = arr.concat(res.result[0].dictList);
          })
          .finally(() => {
            this.loading = false;
          });
      },
      // 查询打卡核销统计
      getActivityOrderCount() {
        activityOrderCount(this.queryParams).then(response => {
          this.info = response.result
        });
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        activityOrderList(this.queryParams).then(response => {
          this.tabList = response.result.records;
          this.total = response.result.total;
          this.loading = false;
        });
      },
      // 表单重置
      resetQuery() {
        this.date = []
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          activityName: '', //活动名称
          buyEndTime: '', //下单结束时间
          buyStartTime: '', //下单开始时间
          couponStatus: '', //使用状态 shenye_punch_activity_order_coupon_status	
          customerName: '', //姓名
          orderNo: '', //订单编号
          orderType: '', //订单类型 shenye_punch_activity_order_type
          phone: '', //手机号码
          remark: '', //备注
          status:'',//支付状态
        }
        // this.resetForm("form");
        this.getList();
        this.getActivityOrderCount()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.buyStartTime = this.date[0];
        this.queryParams.buyEndTime = this.date[1];
        this.queryParams.pageNum = 1;
        this.getList();
        this.getActivityOrderCount()
      },
      //退款
      refundClick(item) { //退款操作
        this.dialogId = item.id
        this.dialogVisible = true
      },
      //退款申请
      applicationClick(item){
        this.dialogId = item.id
        this.applicationVisible = true
      },
      couponNoDialogClick(item) { //查看券码
        this.dialogId = item.orderNo
        this.orderType = item.orderType
        this.couponNoDialogVisible = true
      },
      _handleSuccess(e) {
        //成功回调
        // this.resetQuery()
        this.getList()
        this.getActivityOrderCount()
      },
    }
  };

</script>
<style scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .listBox_head {
    width: 100%;
    padding-bottom: 20px;
  }

  .num_detail {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    border: 1px solid #dfe6ec;
    border-radius: 10px;
    padding: 20px 10px 0;
    margin-bottom: 20px;
  }

  .num_detail_box {
    color: #333;
    font-size: 15px;
    margin-right: 30px;
    margin-bottom: 20px;
  }

</style>
